//
//  TTNewOrderDetailViewController.m
//  TaoTuo
//
//  Created by apple on 2020/12/11.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTNewOrderDetailViewController.h"
#import "TTDiamondInfoTableViewCell.h"
#import "TTOrderDiamondTableViewCell.h"
#import "TTBeInsetTableViewCell.h"
#import "TTExistGoodsTableViewCell.h"
#import "TTPayRecordCell.h"
#import "TTBankCardViewCell.h"
#import "TTPayHintViewCell.h"
#import "TTDianpuImageViewCell.h"

@interface TTNewOrderDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation TTNewOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColorHex(EDEDED);
    [self setupDatas];
    
    
    
}

- (void)setupDatas
{
    TTDiamondInfoCellModel *model1 = [TTDiamondInfoCellModel setModelWithTitle:@"阿萨德刚" hintString:@"按时来得快根据复核" rightString:@"阿萨德股份" target:self selector:@selector(insertAction:)];
    [model1 setCornerRadius:10 cornerType:CornerTypeWithTop];
    [self.dataArray addObject:model1];
    
    [self.dataArray addObject:[TTDiamondInfoCellModel setModelWithTitle:@"的弗兰克" hintString:@"按时股份回购" rightString:@"科技部" target:self selector:@selector(test:)]];
    
    
    TTDiamondInfoCellModel *model2 = [TTDiamondInfoCellModel setModelWithTitle:@"一好看不加你" hintString:@"拉斯可能的赶紧但是，福建高考" rightString:@"UI为何能看见过" target:self selector:@selector(insertAction:)];
    [model2 setCornerRadius:10 cornerType:CornerTypeWithBottom];
    [self.dataArray addObject:model2];
    
    [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TTDiamondInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([TTDiamondInfoTableViewCell class])];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    TTDiamondInfoCellModel *cellModel = self.dataArray[indexPath.row];
    if (cellModel.target && cellModel.selector) {
        [cellModel.target performSelector:cellModel.selector withObject:cellModel];
    }
}

- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.rowHeight = kDiamondInfoCellHeight;
        _tableView.backgroundColor = self.view.backgroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[TTDiamondInfoTableViewCell class] forCellReuseIdentifier:NSStringFromClass([TTDiamondInfoTableViewCell class])];
        [_tableView registerClass:[TTOrderDiamondTableViewCell class] forCellReuseIdentifier:NSStringFromClass([TTOrderDiamondTableViewCell class])];
        [_tableView registerClass:[TTBeInsetTableViewCell class] forCellReuseIdentifier:NSStringFromClass([TTBeInsetTableViewCell class])];
        [_tableView registerClass:[TTExistGoodsTableViewCell class] forCellReuseIdentifier:NSStringFromClass([TTExistGoodsTableViewCell class])];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TTPayRecordCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([TTPayRecordCell class])];
        [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TTBankCardViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([TTBankCardViewCell class])];
        [_tableView registerClass:[TTPayHintViewCell class] forCellReuseIdentifier:NSStringFromClass([TTPayHintViewCell class])];
        [_tableView registerClass:[TTDianpuImageViewCell class] forCellReuseIdentifier:NSStringFromClass([TTDianpuImageViewCell class])];
        _tableView.tableFooterView = [UIView new];
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_topLayoutGuideBottom).offset(50);
            make.left.mas_equalTo(10);
            make.right.equalTo(self.view.mas_right).offset(-10);
            make.bottom.equalTo(self.mas_bottomLayoutGuideBottom);
        }];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

@end
